package com.taobao.action;

import java.util.List;

import com.taobao.factory.TBRunnable;
import com.taobao.pojo.Task;
import com.taobao.server.FilterServer;
import com.taobao.server.ManagerServer;
import com.taobao.server.RoomTaskServer;
import com.taobao.ui.widget.RoomTaskWidget;

public class RoomTaskAction extends CommonAction {
	private RoomTaskServer roomTaskServer;
	private ManagerServer managerServerSingle;
	private FilterServer filterServerSingle;

	@Override
	public void doAction(Object uiObject) {
		final RoomTaskWidget roomTaskWidget = (RoomTaskWidget) uiObject;
		managerServerSingle.addManaged(this, new Object[] { roomTaskWidget });
		Thread thread = new Thread(new TBRunnable() {
			public void run() {
				while (!getThis().isStop()) {
					checkPauseStatus(getThis(), managerServerSingle);
					List<Task> tasks = roomTaskServer.getRoomTasks(filterServerSingle.getFilter());
					checkErrorStatus(getThis(), managerServerSingle, tasks);
					if(tasks != null){
						roomTaskWidget.setTableTasks(tasks);
					}
					sleep(3000);
				}
			}
		});
		thread.setName(getActionName());
		thread.start();
	}

}
